<?php
header("Content-type: image/png");
session_start();
$x = 100;
$y = 30;
$i = 0;
$image = imagecreatefrompng('fond.png');
$c1 = imagecreatefrompng('c1.png');
$c2 = imagecreatefrompng('c2.png');
$c3 = imagecreatefrompng('c3.png');
$c4 = imagecreatefrompng('c4.png');
$c5 = imagecreatefrompng('c5.png');
$c6 = imagecreatefrompng('c6.png');
$c7 = imagecreatefrompng('c7.png');
$c8 = imagecreatefrompng('c8.png');
$c9 = imagecreatefrompng('c9.png');
$noir = imagecolorallocate($image, 0, 0, 0);
$gris = imagecolorallocate($image, 128, 128, 128);
$images = array($c1, $c2, $c3, $c4, $c5, $c6, $c7, $c8, $c9);
$chiffres = array (mt_rand(0, 8), mt_rand(0, 8), mt_rand(0, 8), mt_rand(0, 8), mt_rand(0, 8));
for($i = 0; $i < 5 ; $i++) {
	imagecopymerge($image, $images[$chiffres[$i]], $i*20, 1, 0, 0, 19, 28, 100);
}
for($i = 0; $i < 12; $i++) {
	imageline($image, mt_rand(1, $x - 1), mt_rand(1, $y - 1), mt_rand(1, $x - 1), mt_rand(1, $y - 1), $gris);
}
for($i = 0; $i < 70; $i++) {
	imagesetpixel($image, mt_rand(1, $x - 1), mt_rand(1, $y - 1), $gris);
}
imagerectangle($image, 0, 0, $x - 1, $y - 1, $noir);
$_SESSION['verif_code'] = NULL;
for($i = 0; $i < 5; $i++)
{
	$_SESSION['verif_code'] .= $chiffres[$i]+1;
}
imagepng($image);
?>